/*
 * @Author: Yaodecheng
 * @Date: 2020-11-18 15:19:25
 * @LastEditTime: 2020-11-18 15:22:21
 * @LastEditors: Yaodecheng
 * @Description: 
 */
// Serial.h

#ifndef __SERIAL_H__
#define __SERIAL_H__

#include <stdio.h>	/*标准输入输出定义*/
#include <stdlib.h> /*标准函数库定义*/

#include <unistd.h> /*Unix 标准函数定义*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>	 /*文件控制定义*/
#include <termios.h> /*PPSIX 终端控制定义*/
#include <errno.h>	 /*错误号定义*/
#include <stdint.h>
using namespace std;
class serialPort
{
private:
	int fd;
	struct termios Opt;
	void set_speed(int speed);
	int set_Parity(int databits, int stopbits, int parity);

public:
	serialPort();

	//打开方式1-1
	bool OpenPort(const char *dev);
	//打开方式1-2
	int setup(int speed, int flow_ctrl, int databits, int stopbits, int parity);
	//打开方式2
	int InitSerialPort(const char *COM_NAME, int WhichCom, int BaudRate, int DataBits, int StopBits, int ParityBit);
	int Open(const char *dev, int BaudRate);

	int readBuffer(uint8_t *buffer, int size);
	int writeBuffer(uint8_t *buffer, int size);

	uint8_t getchar();
	int ReadChar(uint8_t &cRecved);
	int ReadChar(char &cRecved);

	void ClosePort();
};
#endif
